home *** CD-ROM | disk | FTP | other *** search
- { Tips & Tricks Issue 12 }
-
- {LISTING 1}
- ...
- type
- EThunkError = class(Exception);
-
- initialization
- if Win32Platform <> Ver_Platform_Win32_Windows then
- raise EThunkError.Create('Flat thunks only supported under Windows 95');
- end.
-
-
- {LISTING 2}
- procedure TFMain.CreateShow(const TFClass : TFormClass; var Reference);
- begin
- TForm(Reference) := TFClass.create(application);
- try
- TForm(Reference).showmodal;
- finally
- TForm(Reference).free;
- end;
- end;
-
-
- {LISTING 3}
- uses SysUtils;
-
- function DirExists(Dir : string) : boolean;
- var fRec : TSearchRec;
- begin
- if (Dir[ Length(Dir) ] = '\') then
- Dec(Dir[0]); { No '\' at the end }
-
- case Length(Dir) of
- 0, 1 : Result := false; { Error }
- 2 : Result := (Dir[2] = ':') and
- (DiskFree(Ord(Dir[1])-64) <> -1); { Root directory }
- else
- Result := (FindFirst(Dir, faDirectory, fRec) = 0); { Directory }
- FindClose(fRec);
- end;
- end;
- ----------------------------------------------------------------------
-
-
- {LISTING 4}
- uses WinTypes, WinProcs, ToolHelp;
-
- procedure ExecuteAndWait(Command : string);
- var
- ModuleID : THandle;
- TaskEntry : TTaskEntry;
- TaskCount : integer;
- TaskList : array [1..100] of THandle; { More than 100 tasks ??? }
- i : integer;
- begin
- TaskEntry.dwSize := SizeOf(TTaskEntry); { Has to be initalized }
- TaskCount := 0;
- if TaskFirst(@TaskEntry) then { Save list of active tasks }
- repeat
- Inc(TaskCount);
- TaskList[TaskCount] := TaskEntry.hTask;
- until (not TaskNext(@TaskEntry));
- Command := Command + #0;
- ModuleID := WinExec(@Command[1], SW_SHOWNOACTIVATE); { Execute }
- if (ModuleID <= hInstance_Error) then
- { Error, Report the error }
- else
- if TaskFirst(@TaskEntry) then { Search for new task }
- repeat
- if (TaskEntry.hModule = ModuleID) then { Task uses same module }
- for i := 1 to TaskCount do
- { Search through list }
- if (TaskList[i] <> TaskEntry.hTask) then begin
- { Found }
- repeat
- { Wait for termination }
- Application.ProcessMessages;
- until (not IsTask(TaskEntry.hTask)) or Application.Terminated;
- exit;
- end;
- until (not TaskNext(@TaskEntry));
- end;
- ----------------------------------------------------------------------
-
-
- {LISTING 5}
- procedure TF_Main.DetailGridDrawDataCell(Sender: TObject;
- const Rect: TRect; Field: TField; State: TGridDrawState);
- begin
- If DetailTable.FieldByName('Row Index').AsInteger In [1,7,8,14] Then
- With (Sender as TDBGrid).Canvas Do
- Begin
- If gdSelected in State Then Brush.Color:=clGreen {further hilite cell}
- Else Brush.Color:=clAqua; {highlight for weekends}
- End;
- DetailGrid.DefaultDrawDataCell(Rect,Field,State);
- end;